import { Entity, Column, ManyToOne, OneToMany } from 'typeorm';
import {IsInt, IsNotEmpty, Min} from 'class-validator'
import { CommonEntity } from '@/common/entities/common.entity';
import {  ReducibleTimeType } from '../dto/common.type';
import { Organization } from '@/modules/organization/models/organization.entity';
import { Card } from '@/modules/card/models/card.entity';

@Entity('course')
export class Course extends CommonEntity{
    @Column({
        comment:'课程名称',
        default:'',
    })
    @IsNotEmpty()
    name:string;
    @Column({
        type:'text',
        comment:'课程描述',
        nullable: true,
    })
    desc:string;
    @Column({
        comment:'适龄人群',
        nullable: true,
    })
    @IsNotEmpty()
    group:string;
    @Column({
        comment:'适合基础',
        nullable: true,
    })
    @IsNotEmpty()
    baseAbility:string;
    @Column({
        comment:'限制上课人数',
        // nullable: true,
    })
    @IsInt()
    @Min(0)
    @IsNotEmpty()
    limitNumber:number;
    @Column({
        comment:'持续时间',
        // nullable: true,
    })
    @IsNotEmpty()
    duration:number;
    @Column({
        comment:'预约信息',
        nullable: true,
    })
    reserveInfo:string;
    @Column({
        comment:'退款信息',
        nullable: true,
    })
    refundInfo:string;
    @Column({
        comment:'其他说明信息',
        nullable: true,
    })
    otherInfo:string;
    // 使用'simple-json'可以将ReducibleTime强行转为字符串
    @Column('simple-json', {
        comment:'可约时间',
        nullable: true,
    })
    reducibleTime:ReducibleTimeType[];

    @ManyToOne(()=>Organization,(org)=>org.courses,{cascade:true})
    org:Organization;

    @OneToMany(()=>Card,(card)=>card.course)
    cards:Card;
}